Skip to main content

Users

Retrieve and modify user records using HTTP methods.

User object

Defines the structure of a user resource returned by the Fake Store API.

{

"id": "integer",

"email": "string",

"username": "string",

"password": "string",

"name": {
"firstname": "string",
"lastname": "string"
},

"address": {
"city": "string",
"street": "string",
"number": "integer",
"zipcode": "string",
"geolocation": {
"lat": "string",
"long": "string"
}
},

"phone": "string"

}

GET /users

Retrieves a list of all user data in the Fake Store API.

Make request

  • Endpoint: /users

  • Method: GET

Request

curl https://fakestoreapi.com/users

Response

  • Status: 200 OK

  • Content-Type: application/json

[
{
"address": {
"geolocation": {
"lat": "-37.3159",
"long": "81.1496"
},
"city": "kilcoole",
"street": "new road",
"number": 7682,
"zipcode": "12926-3874"
},
"id": 1,
"email": "john@gmail.com",
"username": "johnd",
"password": "m38rmF$",
"name": {
"firstname": "john",
"lastname": "doe"
},
"phone": "1-570-236-7033",
"__v": 0
}
]

GET /users/{id}

Retrieves a single user by ID.

Make request

  • Endpoint: /users/{id}

  • Method: GET

  • Path parameter: id (integer)

Request

curl https://fakestoreapi.com/users/{id}

Replace {id} with a valid ID:

curl https://fakestoreapi.com/users/2

Response

  • Status: 200 OK

  • Content-Type: application/json

{
"address": {
"geolocation": {
"lat": "-37.3159",
"long": "81.1496"
},
"city": "kilcoole",
"street": "Lovers Ln",
"number": 7267,
"zipcode": "12926-3874"
},
"id": 2,
"email": "morrison@gmail.com",
"username": "mor_2314",
"password": "83r5^_",
"name": {
"firstname": "david",
"lastname": "morrison"
},
"phone": "1-570-236-7033"
}

For non-existing integer IDs, the API returns 200 OK with a null response body.

Error response

For non-integer IDs, the API returns a JSON-formatted error response.

  • Status: 400 Bad Request
{
"status":"error",
"message":"user id should be provided"
}

POST /users

Creates a new user record.

Make request

  • Endpoint: /users

  • Method: POST

  • Headers: Content-Type: application/json

  • Request body:

{
"username": "johndoe",
"email": "johndoe@gmail.com",
"password": "johndoe10"
}

Request

curl -X POST https://fakestoreapi.com/users \
-H "Content-Type: application/json" \
-d '{"username": "johndoe","email": "johndoe@gmail.com","password": "johndoe10"}'

Response

  • Status: 201 Created

  • Content-Type: application/json

{
"id":1
}

The API returns only the generated ID.

Edge cases

  • The id field is automatically generated by the API and should not be included in the request body.

  • The API does not require a request body and returns 201 Created when absent.

  • Where the request body contains invalid JSON, the API returns a 400 Bad Request error.

PUT /users/{id}

Updates a specified user by ID.

Make request

  • Endpoint: /users/{id}

  • Method: PUT

  • Headers: Content-Type: application/json

  • Path parameter: id (integer)

  • Request body:

{
"id":2,
"username": "johndoe",
"email": "johndoe@gmail.com",
"password": "johndoe80"
}

Request

curl -X PUT https://fakestoreapi.com/users/2 \
-H "Content-Type: application/json" \
-d '{"id":2,"username":"johndoe","email":"johndoe@gmail.com","password":"johndoe80"}'

Response

  • Status: 200 OK

  • Content-Type: application/json

{
"id":2,
"username":"johndoe",
"email":"johndoe@gmail.com",
"password":"johndoe80"
}

Error response

The API returns an error response when non-integers are placed in the {id} field.

  • Status: 400 Bad Request
{
"status":"error",
"message":"something went wrong! check your sent data"
}

Edge cases

  • The request body is not enforced by the API.

  • The API response mirrors the JSON-formatted request.

  • An empty request body returns a 200 OK status.

DELETE /users/{id}

Simulates the removal of a user by ID.

Make request

  • Endpoint: /users/{id}

  • Method: DELETE

  • Path parameter: id (integer)

Request

curl -X DELETE https://fakestoreapi.com/users/{id}

Replace {id} with a valid user ID:

curl -X DELETE https://fakestoreapi.com/users/2

Response

  • Status: 200 OK

  • Content-Type: application/json

{
"address":{
"geolocation":{
"lat":"-37.3159",
"long":"81.1496"
},
"city":"kilcoole",
"street":"Lovers Ln",
"number":7267,
"zipcode":"12926-3874"
},
"id":2,
"email":"morrison@gmail.com",
"username":"mor_2314",
"password":"83r5^_",
"name":{
"firstname":"david",
"lastname":"morrison"
},
"phone":"1-570-236-7033"
}

For non-existing integer IDs, the API returns a 200 OK response and a null body.

Error response

The API returns an error response for non-integer IDs.

  • Status: 400 Bad Request
{
"status":"error",
"message":"user id should be provided"
}